package de.unibi.mmi.homeauto.team1.mainview;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import de.unibi.mmi.homeauto.team1.R;
import de.unibi.mmi.homeauto.team1.constants.Constants.MMIPreference;
import de.unibi.mmi.homeauto.team1.drafts.DraftFragment;

public class OptionsFragment extends DraftFragment {

	public View mainView;
	
	public OptionsFragment(){
		super();
		backgroundID = R.drawable.gears_background;
	}

	public void update() {
		final EditText editText = (EditText) mainView
				.findViewById(R.id.serveraddressedittext);
		editText.setText((String) this.mva.getServerAddress());

		final EditText editText2 = (EditText) mainView
				.findViewById(R.id.serverportedittext);
		editText2.setText(String.valueOf(this.mva.getServerPort()));
	}

	@Override
	public String getTitle() {
		return "Optionen";
	}

	@Override
	protected int getLayoutID() {
		return R.layout.options;
	}

	@Override
	protected void loadComponents(View view) {
		mainView = view;
		final EditText editText = (EditText) mainView
				.findViewById(R.id.serveraddressedittext);
		editText.setText((String) this.mva.getServerAddress());

		final EditText editText2 = (EditText) mainView
				.findViewById(R.id.serverportedittext);
		editText2.setText(String.valueOf(this.mva.getServerPort()));

		Button saveButton = (Button) mainView.findViewById(R.id.savebutton);
		saveButton.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mva.setPreference(MMIPreference.SERVERADDRESS, editText
						.getText().toString())
						&& mva.setPreference(MMIPreference.SERVERPORT, Integer
								.parseInt(editText2.getText().toString()))) {
					mva.newClient();
				}
			}
		});
	}

	@Override
	protected void serverValuesUpdated() {
		// TODO Auto-generated method stub

	}

}